﻿@model pgnSoft.Veloz.ERP.Models.PageModel

<div class="simple_menu top_language_menu">
    @{List<string> DisplayedLangages = new List<string>(); }
    <ul>
        <li>
            <a href="@Url.Action("Index", "Main", new { lang = Model.CurrentCultureInfo.ToString() })">
                <img src="@Model.GetCultureInfoFlagIcon(Model.CurrentCultureInfo.ToString())" />
                @Model.CurrentCultureInfo.ToString()</a>
            @{DisplayedLangages.Add(Model.CurrentCultureInfo.ToString());}
        </li>

        @if (Model.UserLanguages.Count > 0)
        {
            foreach (System.Globalization.CultureInfo cultura in Model.UserLanguages)
            {
                if (Model.CurrentCultureInfo.LCID == cultura.LCID)
                {
                    //anything happens
                }
                else
                {
                    if (!DisplayedLangages.Contains(cultura.ToString()))
                    {
                        DisplayedLangages.Add(cultura.ToString());
                        <li>
                            <a href="@Url.Action("Index", "Main", new { lang = cultura.ToString() })">
                                <img src="@Model.GetCultureInfoFlagIcon(cultura.ToString())" />
                                @cultura.ToString()</a>
                        </li>
                    }
                }
            }
        }

        @{
            string OtherLanguage = global::Resources.strings.Languages_OtherLanguage;
        }
        @if (global::Resources.languages.terms.Split(';').Length > 2)
        {
            <li>
                <a href="#">@OtherLanguage<span class="caret"></span></a>
                <ul>
                    @foreach (string term in global::Resources.languages.terms.Split(';'))
                    {
                        bool contem = false;
                        foreach (System.Globalization.CultureInfo cultura in Model.UserLanguages)
                        {
                            if (cultura.ToString() == term)
                            {
                                contem = true;
                                break;
                            }
                        }

                        if (contem)
                        {
                            //nothing to do
                        }
                        else if(!DisplayedLangages.Contains(term))
                        {
                            DisplayedLangages.Add(term);
                            <li>
                                <a href="@Url.Action("Index", "Main", new { lang = term.ToString() })">
                                    <img src="@Model.GetCultureInfoFlagIcon(term)" />
                                    @term</a></li>
                        }
                    }
                </ul>
            </li> 
        }
        else
        {
            foreach (string term in global::Resources.languages.terms.Split(';'))
            {
                bool contem = false;
                foreach (System.Globalization.CultureInfo cultura in Model.UserLanguages)
                {
                    if (cultura.ToString() == term)
                    {
                        contem = true;
                        break;
                    }
                }

                if (contem)
                {
                    //nothing to do
                }
                else if (!DisplayedLangages.Contains(term))
                {
                    DisplayedLangages.Add(term);
                    <li>
                        <a href="@Url.Action("Index", "Main", new { lang = term.ToString() })">
                            <img src="@Model.GetCultureInfoFlagIcon(term)" />
                            @term</a>
                    </li>
                }
            }
        }
    </ul>
</div>
@*--simple_menu*@
